package top.wuyang.springboot3.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.wuyang.springboot3.base.PageBean;
import top.wuyang.springboot3.base.R;
import top.wuyang.springboot3.entity.TbClass;
import top.wuyang.springboot3.entity.TbStudent;
import top.wuyang.springboot3.service.TbStudentService;
import top.wuyang.springboot3.vo.PageVO;

@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
public class TbStudentController {
    private final TbStudentService tbStudentService;

    @PostMapping("")
    public R<String> insert(@RequestBody TbStudent tbStudent) {
        return tbStudentService.insert(tbStudent);
    }

    @GetMapping("/{pn}/{ps}")
    public R<PageVO<TbStudent>> query(@PathVariable("pn") Long pageNumber, @PathVariable("ps") Long pageSize, TbStudent tbStudent) {
        return tbStudentService.query(tbStudent, PageBean.instance(pageNumber, pageSize));
    }

    @GetMapping("/{id}")
    public R<TbStudent> queryByKey(@PathVariable("id") Integer id) {
        return tbStudentService.queryByKey(id);
    }

    @PutMapping("")
    public R<String> update(@RequestBody TbStudent tbStudent) {
        return tbStudentService.update(tbStudent);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbStudentService.delete(id);
    }



}
